package assets.scripts {
	import mx.controls.Alert;
	import mx.core.Application;
	import mx.events.CloseEvent;
	import mx.messaging.messages.ErrorMessage;
	import mx.rpc.events.FaultEvent;
	
	
    [Bindable]
	public class ControleErro {
		
		public function onFault(event:FaultEvent):void {
			
			var errorMessage:ErrorMessage = event.message as ErrorMessage;
			
			if(errorMessage != null) {
				
				if(errorMessage.rootCause != null && errorMessage.rootCause.message != null && errorMessage.rootCause.message.indexOf('SessaoExpiradaException') > -1) {
					
					if(!Application.application.sessaoExpirada) {
						Application.application.sessaoExpirada = true;
						Alert.show('Sessão expirada, favor efetuar login novamente.', 'Sessão expirada', mx.controls.Alert.OK , null, sairAplicacao);
					}
					
				} else {
					if(!Application.application.sessaoExpirada) {
						Alert.show(event.fault.message);
					}
				}
			} else {
				
				Alert.show(event.fault.message);
				
			}
			
		}
		
		public function sairAplicacao(event:CloseEvent):void{
			  if(event.detail == Alert.OK)
			  	Application.application.sair()
		}
		
	}

}